package com.example.myapplication.apter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.OrderlistBean;

import java.util.List;

public class FoodApter extends  RecyclerView.Adapter<FoodApter.MyHolder>{
    private Context context ;
    private List<OrderlistBean.RowsDTO.OrderInfoDTO.OrderItemListDTO> list;
    private View view;


    public FoodApter(Context context, List<OrderlistBean.RowsDTO.OrderInfoDTO.OrderItemListDTO> list) {
        this.context = context;
        this.list = list;

    }

    @NonNull
    @Override
    public FoodApter.MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //填充试图
        view = LayoutInflater.from(context).inflate(R.layout.item_foodlist,null);
        return new FoodApter.MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull FoodApter.MyHolder holder, int position) {
        String productImage = list.get(position).getProductImage();
        Glide.with(context).load(TokenBean.IP +productImage).into(holder.productImage);
        holder.productName.setText(list.get(position).getProductName());

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        ImageView productImage;
        TextView productName;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            productImage = itemView.findViewById(R.id.productImage);
            productName = itemView.findViewById(R.id.productName);

        }
    }
}


